package com.dcd.util;

import com.google.gson.Gson;

public class JsonUtil {
    private JsonUtil(){}

    private static Gson gson = new Gson();

    /**
     * 将Json字符串转换成对应对象
     * @param jsonString	Json字符串
     * @param clazz		对应字节码文件.class
     * @return
     */
    @SuppressWarnings("unchecked")
    public static<T> T jsonToObject(String jsonString, Class<T> clazz){
        if (clazz == String.class) {
            return (T) jsonString;
        } else {
            return (T)gson.fromJson(jsonString, clazz);
        }
    }
}
